﻿using System;
using System.Text.RegularExpressions;
using System.Web;
using System.Text;

namespace Common
{
    /// <summary>
    /// 字符串 公共类
    /// </summary>
    public class StringManager
    {
        /// <summary>
        /// 根据分隔符和索引提取按照制定字符分隔的字符串
        /// </summary>
        /// <param name="str">按照制定字符分隔的字符串</param>
        /// <param name="sign">分隔符</param>
        /// <param name="index">索引，从0开始</param>
        /// <returns></returns>
        public static string getStringByIndex(string str, char sign, int index)
        {
            string strReturn = "";
            string[] strArray = str.Split(sign);
            if (strArray.Length > 0 && strArray.Length > index)
            {
                strReturn = strArray[index];
            }
            else
            {
                strReturn = (index == 0) ? str : string.Empty;
            }
            return strReturn;
        }

        #region 老系统网站优化里的网站标题和关键字都存在KeyWords字段中，用此方法分隔
        /// <summary>
        /// KeyWords里包含网站标题以"$"分隔
        /// </summary>
        /// <param name="KeyWords"></param>
        /// <returns>string[0]—KeyWords，string[1]-Title</returns>
        public static string[] GetTitleAndKeyWords(string KeyWords)
        {
            string[] returnStr = new string[2];
            if (KeyWords.IndexOf("$") != -1)
            {
                returnStr = KeyWords.Split('$');
            }
            else
            {
                returnStr[0] = KeyWords;
                returnStr[1] = "";
            }
            return returnStr;
        }
        #endregion

        /// <summary>
        /// 获取指定位数的随机数。
        /// </summary>
        /// <param name="rndNumCount">随机数位数。</param>
        /// <returns></returns>
        public static string GetRandomStr(int rndNumCount)
        {
            #region
            string randomStr = "";
            Random Rnd = new Random();
            for (int i = 1; i <= rndNumCount; i++)
            {
                randomStr += Rnd.Next(0, 9).ToString();
            }
            return randomStr;
            #endregion
        }

        /// <summary>
        /// 定长截取没有HTML的字符串+ ... 
        /// </summary>
        /// <param name="value">字符串内容</param>
        /// <param name="len">长度</param>
        /// <returns></returns>
        public static string subHtmlString(object value, int len)
        {
            string outputStr = ClearHTML(value.ToString());
            if (outputStr.Length < len)
                return outputStr;//Encoding.Default.GetBytes(x).Length
            else
                return outputStr.Substring(0, len) + "...";

            //string pattern = @"<[^<>]+>";
            //Regex rgx = new Regex(pattern);
            //string outputStr = rgx.Replace(value.ToString(), "").Replace("&nbsp;", " ");
            //if (outputStr.Length < len)
            //    return outputStr;//Encoding.Default.GetBytes(x).Length
            //else
            //    return outputStr.Substring(0, len) + "...";
        }

        /// <summary>
        /// 截取固定长度的字符串(以Length数量)
        /// </summary>
        /// <param name="str">字符串内容</param>
        /// <param name="len">长度</param>
        /// <param name="flag">true加入...</param>
        /// <returns></returns>
        public static string SubString(string str, int len, bool flag)
        {
            #region
            if (string.IsNullOrEmpty(str)) return "";
            int length = str.Length;
            if (length > len)
            {
                str = str.Substring(0, len);
                if (flag)
                {
                    str = str + "...";
                }
            }
            return str;
            #endregion
        }

        #region 根据字节数长度来截取字符串。加省略号。
        /// <summary>
        /// 根据字节数长度来截取字符串。加省略号。
        /// </summary>
        /// <param name="value">字符串</param>
        /// <param name="length">字节数</param>
        /// <returns></returns>
        public static String SubByte(object value, int length)
        {
            if (length < 1) 
            {
                return value.ToString();
            }
            byte[] bytes = Encoding.Unicode.GetBytes(value.ToString());
            int len = bytes.GetLength(0);
            if (len > length)
            {
                int n = 0;
                int i = 0;
                for (; i < len && n < length; i++)
                {
                    if (i % 2 == 0)
                    {
                        n++;
                    }
                    else
                    {
                        if (bytes[i] > 0)
                        {
                            n++;
                        }
                    }

                }
                if (i % 2 == 1)
                {
                    if (bytes[i] > 0)
                        i = i - 1;
                    else
                        i = i + 1;
                }
                return Encoding.Unicode.GetString(bytes, 0, i) + (bytes.Length > length ? "..." : string.Empty);
            }
            return value.ToString();
        }
        #endregion

        /// <summary>
        /// 取得固定长度的字符串(按单字节截取)。
        /// </summary>
        /// <param name="source">源字符串</param>
        /// <param name="resultLength">截取长度</param>
        /// <returns></returns>
        public static string SubString(string source, int resultLength)
        {
            #region
            //判断字串是否为空
            if (source == null)
            {
                return "";
            }
            //判断字符串长度是否大于截断长度
            if (System.Text.Encoding.Default.GetByteCount(source) > resultLength)
            {

                //初始化
                int i = 0, j = 0;

                //为汉字或全脚符号长度加2否则加1
                foreach (char newChar in source)
                {
                    if ((int)newChar > 127)
                    {
                        i += 2;
                    }
                    else
                    {
                        i++;
                    }
                    if (i > resultLength)
                    {
                        source = source.Substring(0, j);
                        break;
                    }
                    j++;
                }
            }
            return source;
            #endregion
        }

        /// <summary>
        /// 截取 两个字符之间字符串 lzy
        /// </summary>
        /// <param name="str">要截取字符串</param>
        /// <param name="start">开始字符</param>
        /// <param name="end">结束字符</param>
        /// <returns></returns>
        public static string SubStringByChar(string str, char start, char end)
        {
            if (!str.Contains(start.ToString()) || !str.Contains(end.ToString())) return string.Empty;
            return str.Substring(str.IndexOf(start) + 1, str.LastIndexOf(end) - 1 - str.IndexOf(start));
        }

        #region
        /// <summary>
        /// 转换用分隔符分隔的字符串为相应类型的数组
        /// </summary>
        /// <param name="str">字符串</param>
        /// <param name="separator">分隔符</param>
        /// <param name="at">类型</param>
        /// <returns></returns>
        public static object[] ToArray(string str, char separator, DataType at)
        {
            if (string.IsNullOrEmpty(str)) return null;
            string[] sa = str.Split(new char[] { separator }, StringSplitOptions.RemoveEmptyEntries);
            int length = sa.Length;
            object[] o = new object[length];
            for (int i = 0; i < length; i++)
            {
                string s = sa[i];
                switch (at)
                {
                    case DataType.Int:
                        o[i] = Convert.ToInt32(s);
                        break;
                    case DataType.String:
                        o[i] = s;
                        break;
                }
            }
            return o;

        }
        public enum DataType
        {
            Int,
            String
        }
        #endregion

        public static string Escape(string str)
        {
            return Microsoft.JScript.GlobalObject.escape(str);
        }

        public static string Unescape(string str)
        {
            return Microsoft.JScript.GlobalObject.unescape(str);
        }

        ///   <summary>
        ///   去除特定标记
        ///   </summary>
        ///   <returns>已经去除后的文字</returns>
        public static string ClearTheHTML(string Htmlstring)
        {
            #region
            if (!string.IsNullOrEmpty(Htmlstring))
            {
                //删除脚本
                Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "",
                  RegexOptions.IgnoreCase);
                //删除HTML
                Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "",
                  RegexOptions.IgnoreCase);
                //Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "",
                //  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(ldquo|#8220);", "“",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(rdquo|#8221);", "”",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "",
                  RegexOptions.IgnoreCase);
                //Htmlstring = Regex.Replace(Htmlstring, @"[0-9]{3,4}\-[0-9]{7,8}|[0-9]{3,4}[0-9]{7,8}|[0-9]{7,8}$|[0-9]{11}", "",
                //  RegexOptions.IgnoreCase);
                //Htmlstring = Regex.Replace(Htmlstring, @"([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)", "",
                //  RegexOptions.IgnoreCase);
                Htmlstring.Replace("<", "");
                Htmlstring.Replace(">", "");
                //Htmlstring.Replace("\r\n", "");
                Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
            }
            return Htmlstring;
            #endregion
        }
        ///   <summary>
        ///   去除HTML标记
        ///   </summary>
        ///   <param   name="NoHTML">包括HTML的源码   </param>
        ///   <returns>已经去除后的文字</returns>
        public static string ClearHTML(string Htmlstring)
        {
            #region
            if (!string.IsNullOrEmpty(Htmlstring))
            {
                //删除脚本
                Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "",
                  RegexOptions.IgnoreCase);
                //删除HTML
                Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "   ",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(ldquo|#8220);", "“",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&(rdquo|#8221);", "”",
                  RegexOptions.IgnoreCase);
                Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "",
                  RegexOptions.IgnoreCase);
                Htmlstring.Replace("<", "");
                Htmlstring.Replace(">", "");
                Htmlstring.Replace("\r\n", "");
                Htmlstring = System.Web.HttpUtility.HtmlEncode(Htmlstring).Trim();
            }
            return Htmlstring;
            #endregion
        }

        #region 作废
        /// <summary>
        /// 过滤危险字符[不适合html编辑器使用] 多行单行文本框的防sql排除
        /// </summary>
        /// <param name="str">文本内容</param>
        /// <returns></returns>
        public static string HtmlEncode(string str)
        {
            #region
            str = str.Replace("&", "&amp;");
            str = str.Replace("<", "&lt;");
            str = str.Replace(">", "&gt");
            str = str.Replace("'", "''");
            str = str.Replace("*", "");
            str = str.Replace("\n", "<br />");
            str = str.Replace("\r\n", "<br />");
            str = str.Replace("select", "");
            str = str.Replace("insert", "");
            str = str.Replace("update", "");
            str = str.Replace("delete", "");
            str = str.Replace("create", "");
            str = str.Replace("drop", "");
            str = str.Replace("delcare", "");
            str = str.Replace("script", "");
            str = str.Replace("iframe", "");

            if (str.Trim().ToString() == "") { str = ""; }
            return str.Trim();
            #endregion
        }
        #endregion

        ///<summary>
        /// 将HTML自定义格式化转化过来[不适合html编辑器使用]
        ///</summary>
        ///<param name="str">HTML文本内容</param>
        public static string UnHtmlEncode(string str)
        {
            #region
            str = str.Replace("&amp;", "&");
            str = str.Replace("&lt;", "<");
            str = str.Replace("&gt", ">");
            str = str.Replace("''", "'");
            str = str.Replace("<br />", "\r\n");
            if (str.Trim().ToString() == "") { str = " "; }
            return str.Trim();
            #endregion
        }

        /// <summary>
        /// 去除A标签和Script标签
        /// </summary>
        /// <param name="Htmlstring">字符串</param>
        /// <param name="Typeinfo">0去除所有；1只去除script；2只去除A标签</param>
        /// <returns></returns>
        public static string ClearAJS(string Htmlstring, int Typeinfo)
        {
            #region
            switch (Typeinfo)
            {
                case 0:
                    Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                    Htmlstring = Regex.Replace(Htmlstring, @"<a[^>]*?>", "", RegexOptions.IgnoreCase);
                    Htmlstring = Regex.Replace(Htmlstring, @"</a>", "", RegexOptions.IgnoreCase);
                    break;
                case 1:
                    Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                    break;
                case 2:
                    Htmlstring = Regex.Replace(Htmlstring, @"<a[^>]*?>", "", RegexOptions.IgnoreCase);
                    Htmlstring = Regex.Replace(Htmlstring, @"</a>", "", RegexOptions.IgnoreCase);
                    break;
                default:
                    Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
                    Htmlstring = Regex.Replace(Htmlstring, @"<a[^>]*?>", "", RegexOptions.IgnoreCase);
                    Htmlstring = Regex.Replace(Htmlstring, @"</a>", "", RegexOptions.IgnoreCase);
                    break;
            }
            return Htmlstring;
            #endregion
        }

        /// <summary>
        /// 过滤SQL字符
        /// </summary>
        /// <param name="strKey"></param>
        /// <returns></returns>
        public static string ClearSql(string strKey)
        {
            #region
            if (!string.IsNullOrEmpty(strKey))
            {
                //strKey = Regex.Replace(strKey, @"&quot|where|order|and|or|exec|insert|select|delete|drop|update|count|chr|mid|master|truncate|char|declare|cast|%20|0x|\*|'|,|\+|\-|''|;|；", "", RegexOptions.IgnoreCase);
                strKey = strKey.Replace("'", "''");

            }
            return strKey;
            #endregion
        }

        /// <summary>
        /// 过滤所有SQL语句中的非法字符
        /// </summary>
        /// <param name="strKey">输入内容</param>
        /// <returns></returns>
        public static string ClearStrictSql(string inputStr)
        {
            #region
            if (!string.IsNullOrEmpty(inputStr))
            {
                string sqlkey = "select,insert,delete,from,count(,drop table,update,truncate,asc(,mid(,char(,xp_cmdshell,exec master,netlocalgroup administrators,:,net user,or,and,";
                sqlkey = sqlkey + "-,;,/,(,),[,],},{,%,@,*,!,',|";
                string[] strArray = Regex.Split(sqlkey, ",", RegexOptions.IgnoreCase);
                foreach (string i in strArray)
                {
                    inputStr = inputStr.Replace(i, "");
                }
            }
            return inputStr;
            #endregion
        
        }

        /// <summary>
        /// 检查URL参数是否有sql字符
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool CheckUrlSqlChar(string str)
        {
            #region
            if (string.IsNullOrEmpty(str))
                return false;
            // string pattern = @"&quot|where|and|exec|insert|select|delete|drop|update|count|chr|master|truncate|char|declare|cast|%20|0x|\*|'|\--|''|;";

            //// string pattern = @"&quot|where|and|exec|insert|select|delete|drop|update|count|chr|mid|master|truncate|char|declare|cast|%20|0x|\*|'|\--|''|;";
            // Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
            // if (regex.IsMatch(str))
            // {
            //     return true;
            // }
            // else
            // {
            //     return false;
            // }
            //return !Regex.IsMatch(str, @"[-|;|,|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\']");
            return false;
            //return Regex.IsMatch(str, @",|\/|\(|\)|\[|\]|\}|\{|%|@|\*|!|\'");//去掉最外面[]   若带[]里面的字符匹配包括‘|’   lzy  09.15
            #endregion
        }
        /// <summary>
        /// 检查URL参数是否有sql字符  lzy  
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool CheckUrlSql(string str)
        {
            #region
            if (string.IsNullOrEmpty(str))
                return false;
            return Regex.IsMatch(str, @",|'", RegexOptions.IgnoreCase);

            #endregion
        }

        #region 已作废
        ///// <summary>
        ///// 检查Form表单是否有sql字符
        ///// </summary>
        ///// <param name="str"></param>
        ///// <returns></returns>
        //public static bool CheckFormSqlChar(string str)
        //{
        //    #region
        //    string pattern = @"&quot|where|exec|insert|select|delete|drop|update|master|truncate|varchar|declare|%20|0x|\*|\--";
        //    Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
        //    if (regex.IsMatch(str))
        //    {
        //        return true;
        //    }
        //    else
        //    {
        //        return false;
        //    }
        //    #endregion
        //} 
        #endregion


        /// <summary>
        /// 过滤URL参数中的Sql危险字符
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string ClearUrlQuerySql(string url)
        {
            #region
            int index = url.IndexOf('?');
            if (index > -1)
            {
                url = url.Substring(0, index) + ClearSql(url.Substring(index));
            }
            return url;
            #endregion
        }

        #region 字符/ASCII码转换
        public static string CharToAsc(string str)
        {
            System.Text.StringBuilder val = new System.Text.StringBuilder("");
            char temp;
            if (str.Length > 0)
            {
                val.Append(";");
                for (int i = 0; i < str.Length; i++)
                {
                    temp = char.Parse(str.Substring(i, 1));
                    val.Append(((int)temp).ToString());
                    val.Append(";");
                }
            }
            return val.ToString();
        }

        public static string AscTochar(string str)
        {
            System.Text.StringBuilder val = new System.Text.StringBuilder("");
            char ch;
            if (str.Length > 0 && CheckUp(str))
            {
                string[] temp = str.Split(';');
                for (int i = 0; i < temp.Length; i++)
                {
                    if (temp[i].Length <= 0) continue;
                    int asc = int.Parse(temp[i]);
                    ch = (char)asc;
                    val.Append(ch.ToString());
                }
            }
            else
            {
                val.Append(str);
            }
            return val.ToString();
        }

        /// <summary>
        /// 检测字符有效性
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        protected static bool CheckUp(string str)
        {
            bool val = true;
            if (str.Length > 0)
            {
                for (int i = 0; i < str.Length; i++)
                {
                    string temp = str.Substring(i, 1);
                    switch (temp)
                    {
                        case "0": break;
                        case "1": break;
                        case "2": break;
                        case "3": break;
                        case "4": break;
                        case "5": break;
                        case "6": break;
                        case "7": break;
                        case "8": break;
                        case "9": break;
                        case ";": break;
                        default:
                            val = false;
                            break;
                    }
                }
            }
            return val;
        }


        #endregion

        /// <summary>
        /// 容量大小装换
        /// </summary>
        /// <param name="strSize"></param>
        /// <returns></returns>
        public static string GetSize(int size)
        {
            if (size > 0)
            {
                if (size < 1024)
                {
                    return Convert.ToInt32(size * 100) / 100 + " bytes";
                }
                if (size < 1048576)
                {
                    return Convert.ToInt32((size / 1024) * 100) / 100 + "KB";
                }
                if (size < 1073741824)
                {
                    return Convert.ToInt32((size / 1048576) * 100) / 100 + "MB";
                }
                return Convert.ToInt32((size / 1073741824) * 100) / 100 + "GB";
            }
            else
            {
                return "0KB";
            }
        }
        /// <summary>
        /// 获得颜色
        /// </summary>
        /// <param name="tag"></param>
        /// <returns></returns>
        public static string GetColor(string tag)
        {
            string[] tagArr = tag.Split(',');
            if (tagArr.Length == 0) return "其他颜色";
            tag = tagArr[0];
            string color;
            switch (tag)
            {
                case "white":
                    color = "白色";
                    break;
                case "black":
                    color = "黑色";
                    break;
                case "blue":
                    color = "蓝色";
                    break;
                case "red":
                    color = "红色";
                    break;
                case "green":
                    color = "绿色";
                    break;
                case "violet":
                    color = "紫色";
                    break;
                case "orange":
                    color = "橙色";
                    break;
                case "gray":
                    color = "灰色";
                    break;
                default:
                    color = "其他颜色";
                    break;
            }
            return color;
        }

        /// <summary>
        /// 分割字符串
        /// </summary>
        public static string[] SplitString(string strContent, string strSplit)
        {
            if (!string.IsNullOrEmpty(strContent.Trim()))
            {
                if (strContent.IndexOf(strSplit) < 0)
                    return new string[] { strContent };

                return Regex.Split(strContent, Regex.Escape(strSplit), RegexOptions.IgnoreCase);
            }
            else
                return new string[0] { };
        }

        #region 过滤一些常见非法字符
        /// <summary>
        /// 过滤一些常见非法字符
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        public static String CutWords(string title)
        {
            return title
                .Replace("【", "")
                .Replace("】", "")
                .Replace("★", "")
                .Replace(@"\", "")
                .Replace("！", "")//---
                .Replace("┣", "")
                .Replace("//", "")//---
                .Replace("〓", "")
                .Replace("&", "")
                .Replace("@", "")
                .Replace("☆", "")
                .Replace("≮", "")
                .Replace("◢", "")
                .Replace("◆", "");
        }

        /// <summary>
        /// 过滤超链接title属性中包含的非法字符
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string GetLinkTitle(string input)
        {      

                return input.Replace("\"", "").Replace("'", "");           
        }
        #endregion


        #region 企汇网 新闻详细页分页
        public static readonly string StrSYHPaperBreak = "<%--#SYHpagerbreak#--%>";//企汇网 新闻详细页分页标记符
        private const string PaperBreakHtml = "<div contenteditable=\"false\" class=\"cke_pagebreak\" data-cke-display-name=\"pagebreak\" aria-label=\"Page Break\" title=\"Page Break\" style=\"page-break-after: always;\"></div>";

        /// <summary>
        /// SYH分页标记 转换html分页符 后台用
        /// </summary>
        /// <param name="strContents"></param>
        /// <returns></returns>
        public static string SYHPaperBreakToHtml(string strContents)
        {
            return strContents.Replace(StrSYHPaperBreak, PaperBreakHtml);
        }
        /// <summary>
        /// html分页符 转换SYH分页标记 后台用
        /// </summary>
        /// <param name="strContents"></param>
        /// <returns></returns>
        public static string SYHPaperHtmlToBreak(string strContents)
        {
            string regexstr = @"<div[^>]*page-break-after[^>]*\>([\w\W]*?)\</div\>";
            return Regex.Replace(strContents, regexstr, StrSYHPaperBreak, RegexOptions.IgnoreCase);
        }

        #endregion

        /// <summary>
        /// 设置突出显示字符
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>

        public static string StringBoldword(string strcontent, string word)
        {

            return strcontent.Replace(word, "<span style='color: Red'>" + word + "</span>");
        
        }



        /// <summary>
        /// 采用UTF-8编码方式判断出入字符串中是否含有乱码
        /// </summary>
        /// <param name="txt">出入字符串</param>
        /// <returns></returns>
        public static bool isLuanMa(string txt)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(txt);
            //239 191 189   
            for (int i = 0; i < bytes.Length; i++)
            {
                if (i < bytes.Length - 3)
                    if (bytes[i] == 239 && bytes[i + 1] == 191 && bytes[i + 2] == 189)
                    {
                        return true;
                    }
            }
            return false;
        }   




    }
}
